package com.yanqu.road.entity.player;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class UserVehicle extends DataObject {

	private long userId;

	private String vehicleUid;

	private int templateId;

	private int patronsId;

	private int level;            //等级

	private int breakLv;          //突破等级

	private int studyLv;          //学习等级

	private int equipTimes;       //每日的装备次数

	private int equipBuyTimes;    //每日购买装备次数

	private long createTime;      //获得时间

	private long lastUpdateTime;

	private boolean isDelete;

	private int resetTimes;       //重置次数

	private boolean isLock;		//因改需求,字段弃用

	private List<Integer> soulBlockList = new ArrayList<>();		//魂兽块

	private Map<Integer, UserVehicleSkill> skillMap = new ConcurrentHashMap<>();

	private List<UserVehicleOtherSkill> otherSkillList = new ArrayList<>();

	private int boneLv;
	private int boneHole;

	public UserVehicle() {
	}

	public List<UserVehicleOtherSkill> getOtherSkillList() {
		return otherSkillList;
	}

	public void setOtherSkillList(List<UserVehicleOtherSkill> skillList) {
		this.otherSkillList = skillList;
	}

	public UserVehicleOtherSkill getVehicleOtherSkill(int type, int skillId){
		if(null != otherSkillList) {
			List<UserVehicleOtherSkill> tempSkillList = new ArrayList<>(otherSkillList);
			for (UserVehicleOtherSkill userSkill : tempSkillList){
				if(userSkill.getSkillType() == type && userSkill.getSkillId() == skillId){
					return userSkill;
				}
			}
		}
		return null;
	}

	public boolean isContainsSkill(int type, int skillId){
		UserVehicleOtherSkill userSkill = getVehicleOtherSkill(type, skillId);
		return null != userSkill;
	}

	public void addSkill(UserVehicleOtherSkill userSkill){
		otherSkillList.add(userSkill);
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		if (this.userId != userId) {
			this.userId = userId;
			setUpdateOption();
		}
	}

	public int getPatronsId() {
		return patronsId;
	}

	public void setPatronsId(int patronsId) {
		if(this.patronsId != patronsId) {
			this.patronsId = patronsId;
			setUpdateOption();
		}
	}

	public String getVehicleUid() {
		return vehicleUid;
	}

	public void setVehicleUid(String vehicleUid) {
		if(!Objects.equals(this.vehicleUid, vehicleUid)) {
			this.vehicleUid = vehicleUid;
			setUpdateOption();
		}
	}

	public int getTemplateId() {
		return templateId;
	}

	public void setTemplateId(int templateId) {
		if (this.templateId != templateId) {
			this.templateId = templateId;
			setUpdateOption();
		}
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		if(this.level != level) {
			this.level = level;
			setUpdateOption();
		}
	}

	public int getBreakLv() {
		return breakLv;
	}

	public void setBreakLv(int breakLv) {
		if(this.breakLv != breakLv) {
			this.breakLv = breakLv;
			setUpdateOption();
		}
	}

	public int getStudyLv() {
		return studyLv;
	}

	public void setStudyLv(int studyLv) {
		if(this.studyLv != studyLv) {
			this.studyLv = studyLv;
			setUpdateOption();
		}
	}

	public int getEquipTimes() {
		return equipTimes;
	}

	public void setEquipTimes(int equipTimes) {
		if(this.equipTimes != equipTimes) {
			this.equipTimes = equipTimes;
			setUpdateOption();
		}
	}

	public int getEquipBuyTimes() {
		return equipBuyTimes;
	}

	public void setEquipBuyTimes(int equipBuyTimes) {
		if(this.equipBuyTimes != equipBuyTimes) {
			this.equipBuyTimes = equipBuyTimes;
			setUpdateOption();
		}
	}

	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}

	public long getLastUpdateTime() {
		return lastUpdateTime;
	}

	public void setLastUpdateTime(long lastUpdateTime) {
		if (this.lastUpdateTime != lastUpdateTime) {
			this.lastUpdateTime = lastUpdateTime;
			this.setOp(DataStatus.Update);
		}
	}

	public boolean isDelete() {
		return isDelete;
	}

	public void setDelete(boolean delete) {
		if(this.isDelete != delete) {
			isDelete = delete;
			setOp(DataStatus.Update);
		}
	}

	public Map<Integer, UserVehicleSkill> getSkillMap() {
		return skillMap;
	}

	/**
	 * 获取生效的技能
	 * @return
	 */
	public Map<Integer, UserVehicleSkill> getSkillMapEffect() {
		Map<Integer, UserVehicleSkill> map = new HashMap<>();
		for (Map.Entry<Integer, UserVehicleSkill> skillEntry : skillMap.entrySet()) {
			if(skillEntry.getValue().isInvalid()){
				continue;
			}
			map.put(skillEntry.getKey(), skillEntry.getValue());
		}
		return map;
	}

	public void setSkillMap(Map<Integer, UserVehicleSkill> skillMap) {
		this.skillMap = skillMap;
	}

	public int getResetTimes() {
		return resetTimes;
	}

	public void setResetTimes(int resetTimes) {
		if (this.resetTimes != resetTimes) {
			this.resetTimes = resetTimes;
			setUpdateOption();
		}
	}

	public boolean isLock() {
		return this.isLock;
	}

	public void setLock(boolean lock) {
		if (this.isLock != lock) {
			this.isLock = lock;
			setUpdateOption();
		}
	}

    public List<Integer> getSoulBlockList() {
        return soulBlockList;
    }

    public void setSoulBlockList(List<Integer> soulBlockList) {
        this.soulBlockList = soulBlockList;
        setUpdateOption();
    }

	public int getBoneLv() {
		return boneLv;
	}

	public void setBoneLv(int boneLv) {
		if (this.boneLv != boneLv) {
			this.boneLv = boneLv;
			setUpdateOption();
		}
	}

	public int getBoneHole() {
		return boneHole;
	}

	public void setBoneHole(int boneHole) {
		if (this.boneHole != boneHole) {
			this.boneHole = boneHole;
			setUpdateOption();
		}
	}

	/**
	 * 按二进制判断是否解锁
	 *
	 * @param pos
	 * @return
	 */
	public boolean isBoneHoleUnlock(int pos) {
		if (pos < 1 || pos > 9) {
			return false;
		}
		int holeValue = getBoneHole();
		return (holeValue & (1 << (pos - 1))) != 0;
	}
}
